package com.hzlj.position.config.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.hzlj.position.config.cache.NoticeConfigCache;
import com.hzlj.position.config.common.dto.noticeConfig.InitiativeNoticeExtDTO;
import com.hzlj.position.config.common.dto.noticeConfig.InspectionNoticeExtDTO;
import com.hzlj.position.config.common.dto.noticeConfig.NoticeConfigQueryResultDTO;
import com.hzlj.position.config.service.NoticeConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 通知配置(NoticeConfig)表服务接口
 *
 * @author lifh
 * @date 2023-07-18 12:01:39
 */
@Slf4j
@Service
public class NoticeConfigServiceImpl implements NoticeConfigService {
    @Resource
    private NoticeConfigCache noticeConfigCache;


    @Override
    public NoticeConfigQueryResultDTO getNoticeConfigByJgCode(String jgCode) {
        return noticeConfigCache.getNoticeConfigByJgCode(jgCode);
    }

    @Override
    public boolean correctNotice(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        return noticeConfig == null || Boolean.TRUE.equals(noticeConfig.getCorrectNotice());
    }

    @Override
    public boolean warningJzryNotice(String jgCode, String warningType) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        return ObjectUtil.isNotEmpty(noticeConfig)
                && ObjectUtil.isNotEmpty(noticeConfig.getWarningJzryNoticeTypes())
                && noticeConfig.getWarningJzryNoticeTypes().contains(warningType);
    }

    @Override
    public boolean warningGzryNotice(String jgCode, String warningType) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        return ObjectUtil.isNotEmpty(noticeConfig)
                && ObjectUtil.isNotEmpty(noticeConfig.getWarningGzryNoticeTypes())
                && noticeConfig.getWarningGzryNoticeTypes().contains(warningType);
    }

    @Override
    public int reportAutoDelayMinutes(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getReportAutoDelayMinutes() == null) {
            return 60;
        }
        return noticeConfig.getReportAutoDelayMinutes();
    }

    @Override
    public int reportArtificialDelayMinutes(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getReportArtificialDelayMinutes() == null) {
            return 60;
        }
        return noticeConfig.getReportArtificialDelayMinutes();
    }

    @Override
    public int trackCheckDelayMinutes(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getTrackCheckDelayMinutes() == null) {
            return 60;
        }
        return noticeConfig.getTrackCheckDelayMinutes();
    }

    @Override
    public int correctDelayMinutes(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getCorrectDelayMinutes() == null) {
            return 60;
        }
        return noticeConfig.getCorrectDelayMinutes();
    }

    @Override
    public int positionCheckDelayMinutes(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getPositionCheckDelayMinutes() == null) {
            return 60;
        }
        return noticeConfig.getPositionCheckDelayMinutes();
    }


    @Override
    public String defaultMessageNoticeAuths(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || ObjectUtil.isEmpty(noticeConfig.getDefaultMessageNoticeAuths())) {
            return null;
        }
        return String.join(",", noticeConfig.getDefaultMessageNoticeAuths());
    }

    @Override
    public InitiativeNoticeExtDTO initiativeNotices(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getInitiativeNoticeExt() == null) {
            return new InitiativeNoticeExtDTO();
        }
        return noticeConfig.getInitiativeNoticeExt();
    }

    @Override
    public InspectionNoticeExtDTO inspectionNotices(String jgCode) {
        NoticeConfigQueryResultDTO noticeConfig = this.getNoticeConfigByJgCode(jgCode);
        if (noticeConfig == null || noticeConfig.getInspectionNoticeExt() == null) {
            return new InspectionNoticeExtDTO();
        }
        return noticeConfig.getInspectionNoticeExt();
    }
}
